<?php

namespace app\modules\test\controllers;

use app\core\YpBaseController;
use app\services\ProductService;
use app\services\YcfSafe;
use app\models\GoodsInfo;

/**
 * Default controller for the `test` module
 */
class DefaultController extends YpBaseController
{
    public $layout = false;
    /**
     * Renders the index view for the module
     * @return string
     */
    public function actionIndex()
    {
        echo '<h3>hello test module!</h3>';
        //return $this->render('index');
    }

    /**
     * 计算更新gds_product表的字段
     * @author frq
     * @since 2016.11.02
     */
    public function actionUpdateproduct()
    {
        ProductService::updateProduct();
    }

    public function actionSafe()
    {
        //print_r($this->request);die;
        /*$safeStr = YcfSafe::apiHeaderEncrypt('app',array('system'=>'ios', 'version'=>'5.4.0', 'lang'=>'app', 'imei' =>''));
        echo $safeStr."<br/>";die;*/

        $result = YcfSafe::checkHttpHeaders();
        //var_dump($result);
    }

    public function actionEditor()
    {
        /*$array = [12,5,26,18,7,17,9];
        $len = count($array);
        for($i=1;$i<$len;$i++){
            $key = $array[$i];
            $j = $i - 1;
            while($j >= 0 && $key < $array[$i]){
                $array[$j+1] = $array[$j];
                $j-=1;
            }
            $array[$j + 1] = $key;
        }
        print_r($array);
        var_dump(123);*/
        //exit('ddddddd');
        return $this->render('editor');
    }
    public function actionTest()
    {
        //var_dump(123);
        $goodsInfoModel = new GoodsInfo();
        $params         = [
            //'page'  => $page,
            'limit' => 10,
            'where' => [
                'and',
                ['>', 'id', 0],
            ],
            'order' => 'id ASC'
        ];
        $productList = $goodsInfoModel->dbList(['*'], $params);
        //var_dump($productList);
        //$params         = ['where' => ['id' => 9660]];
        $productList    = $goodsInfoModel->dbGet(['*'], '9660');
        $productList    = $goodsInfoModel->dbCount();
        var_dump($productList);

        exit;
    }
}
